<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%
    request.setAttribute("basePath",request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath());
%>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
    <style>
        h2{
            margin-left: 283px;
        }
        input{
            width: 603px;
            height: 36px;
            margin-left: 23px;
            border: 1px solid #CFCFCF;
        }
        input[type=button]{
            width: 253px;
            height: 36px;
            margin-left: 93px;
            cursor: pointer;
            border: 1px solid #CFCFCF;
        }
        select{
            width: 605px;
            height: 36px;
            border: 1px solid #CFCFCF;
            margin-left: 23px;
        }
        textarea{
            width: 600px;
            height: 200px;
            border: 1px solid #CFCFCF;
            margin-left: 23px;
        }
        #modes{
            width: 608px;
            height: auto;
            margin-left: 93px;
        }
    </style>
    <title></title>
    <script src="${basePath}/js/jquery-1.5.2.min.js"></script>
    <script type="text/javascript">
        var controllerJson = [
			{"path":"/func_fans_recharge","des":"粉丝加金币专用接口"},
            {"path":"/test","des":"测试"},
            {"path":"/func_account_sendsms","des":"发送验证短信"},
            {"path":"/func_userid_get","des":"获取用户ID"},
            {"path":"/func_password_login","des":"粉丝密码登录"},
            {"path":"/func_password_login_by_tenant","des":"多投顾粉丝密码登录"},
            {"path":"/func_fans_reset_password","des":"粉丝密码重置"},
            {"path":"/func_mobile_login","des":"手机号登录"},
            {"path":"/func_user_info_complet","des":"完善信息登录"},
            {"path":"/func_check_invitation_code","des":"验证邀请码"},
            
            {"path":"/func_userid_get_by_tenant","des":"多投顾获取用户ID"},
            {"path":"/func_mobile_login_by_tenant","des":"多投顾手机号登录"},
            {"path":"/func_user_info_complet_by_tenant","des":"多投顾完善信息登录"},
            {"path":"/func_fans_follow_broker","des":"粉丝关注大V"},
            {"path":"/func_fans_cancel_follow_broker","des":"粉丝取消关注大V"},
            {"path":"/func_fans_click_broker","des":"粉丝进入大V页面"},
            {"path":"/func_broker_list_by_tenant","des":"多投顾列表"},
            {"path":"/func_broker_dropdown_list_by_tenant","des":"投顾下拉列表"},
            {"path":"/func_get_userinfo_by_code","des":"使用code获取用户信息"},
            {"path":"/func_get_userinfo_by_code_tenant","des":"使用code和租户信息获取用户信息"},
            //{"path":"/func_wx_register","des":"用户手机号注册"},
            {"path":"/func_user_info_qry","des":"查询粉丝信息"},
            {"path":"/func_user_amount_qry","des":"查询粉丝金币数"},
            {"path":"/func_noread_notice_qry","des":"查询未读消息数"},
            {"path":"/func_question_num_qry","des":"粉丝提问数"},
            {"path":"/func_update_user_avatar","des":"粉丝头像修改"},
            {"path":"/func_update_user_name","des":"粉丝昵称修改"},
            //{"path":"/func_recharge_detail_qry","des":"用户充值明细"},
            {"path":"/func_detail_qry","des":"用户明细"},
            {"path":"/func_suggestion_add","des":"用户提建议"},
            {"path":"/func_broker_info_qry","des":"获取大V个人信息"},
            {"path":"/func_broker_info_qry_nologin","des":"获取大V个人信息（未登录获取昵称）"},
            {"path":"/func_stock_list","des":"全市场股票代码列表"},
            //{"path":"/func_stock_task","des":"调用股票更新任务"},
            {"path":"/func_save_system_tag","des":"添加系统标签"},
            {"path":"/func_open_token","des":"获取恒生开放平台AccessToken"},
            {"path":"/func_viewpoint_list_by_fans","des":"观点列表"},
            {"path":"/func_viewpoint_list_by_tenant","des":"观点列表租户级"},
            {"path":"/func_viewpoint_list_by_tenant_nologin","des":"未登录获取租户观点列表"},
            {"path":"/func_get_viewpoint_content","des":"获取单个观点内容"},
            {"path":"/func_viewpoint_replay_detail_list","des":"观点评论引用详细列表"},
            {"path":"/func_viewpoint_tag_list","des":"查询大V标签"},
            {"path":"/func_click_upvote","des":"点赞"},
            {"path":"/func_click_reward","des":"打赏"},
            {"path":"/func_comment_view","des":"评论详情页面"},
            {"path":"/func_comment_view_no_login","des":"评论详情页面(无需登录)"},
            {"path":"/func_question_answer_list_by_fans","des":"问与答列表"},
            {"path":"/func_question_answer_list_by_tenant","des":"多投顾问与答列表"},
            {"path":"/func_question_ask","des":"提问"},
            {"path":"/func_question_ask_by_tenant","des":"多投顾提问"},
            {"path":"/func_answerd_num","des":"被回答问题个数"},
            {"path":"/func_roll_notice_list","des":"获取滚动播报通知"},
            {"path":"/func_get_pay_data","des":"获取调用微信支付JS-SDK的参数"},
            {"path":"/func_comment_save","des":"发表评论"},
            {"path":"/func_pay_callback","des":"微信回调"},
            {"path":"/func_set_his_chat","des":"记录聊天信息"},
            {"path":"/func_get_his_chat","des":"获取聊天历史记录"},
            {"path":"/func_preview_his_chat","des":"从数据库聊天历史记录"},
            {"path":"/func_comment_spitslot_upvote","des":"评论吐槽点赞"},
            {"path":"/func_fans_question_del","des":"粉丝删除自己的提问"},
            //{"path":"/func_updown_market","des":"大盘看涨跌投票"},
            //{"path":"/func_qry_market","des":"查询大盘看涨跌投票"},
            {"path":"/func_customer_logout","des":"粉丝登出"},
            {"path":"/func_fans_adpage_list","des":"粉丝端广告页列表"},
            {"path":"/func_rolling_msg_list_get","des":"滚动消息获取"},
            {"path":"/func_broker_auth_info_get","des":"获取大V授权账户"},
            {"path":"/func_chatroom_onlinenum_by_fans","des":"fans获取在线用户数"},
            {"path":"/func_get_weibo_userinfo_by_code","des":"获取微博用户信息"},
            {"path":"/func_get_qq_userinfo_by_code","des":"获取QQ用户信息"},
            {"path":"/func_payment_option_qry","des":"获取打赏、充值额度"},
            {"path":"/func_get_light_access_token","des":"获取light的Access_token"},
            {"path":"/func_fans_activity_recharge","des":"东北证券国庆活动加金币"},
            {"path":"/func_guest_token","des":"获取访客token"},
            {"path":"/func_extendapp_by_group_fans","des":"获取分组中组件列表"},
            {"path":"/func_fans_app_reg_login","des":"三方注册"},
            {"path":"/func_tenant_info_get","des":"获取租户基础信息"},
            {"path":"/func_fans_point_recharge","des":"粉丝积分新增"},
            {"path":"/func_fans_point_consume","des":"粉丝积分消费"},
            {"path":"/func_fans_point_query_list","des":"粉丝积分流水查询"},
            {"path":"/func_fans_point_query","des":"粉丝积分查询"},
            {"path":"/func_fans_point_query_login","des":"粉丝登录积分查询"},
            {"path":"/func_fans_point_url","des":"粉丝积分入口URL地址"},
            {"path":"/func_live_invest_List","des":"获取直播列表"},
            {"path":"/func_broker_upvote_click","des":"给投顾投票"},
            {"path":"/func_get_vote_record_list","des":"搜索列表"},
            {"path":"/func_action_log","des":"操作行为记录"},
            {"path":"/func_check_sign","des":"校验并加密"},            
            {"path":"/func_history_live_invest_list","des":"历史直播列表"},
            {"path":"/func_company_broker_list","des":"券商投顾列表"},            
            {"path":"/func_get_brokerinfo_by_userid","des":"根据userid获取投顾信息"},
            {"path":"/func_check_sign","des":"校验并加密"},
            {"path":"/func_get_dynamic_list","des":"粉丝端动态推送列表"},
            {"path":"/func_realtime_qry_load_more","des":"粉丝端动态组合的当日成交列表"},
            {"path":"/func_chattopic_list","des":"直播话题列表"},
            {"path":"/func_survey_status_list","des":"调研支付状态列表"},
            {"path":"/func_get_vote_record_list","des":"投票排行查询"},
            {"path":"/func_is_capital_account","des":"是否是资金账号"}
        ];
        var accesstoken = "";
        var usertoken = "";
        $(function () {
            $("#txtConller").append(new Option("请选择", "", true));
            for (var i = 0; i < controllerJson.length; i++) {
                var option = new Option(controllerJson[i].path+"..."+controllerJson[i].des, controllerJson[i].path);
                $("#txtConller").append(option);
            }

            $("#txtConller").change(function(){
                var path = $(this).val();
                $.ajax({
                    url: "/js/testdata.json",
                    type: "GET",
                    dataType: "json",
                    success: function (data) {
                        for(var p in data){//遍历json对象的每个key/value对,p为key
                            if("/"+p==path){
                            	if(typeof(data[p].user_token) != "undefined"){
	                            	data[p].user_token = accesstoken;
                            	}
                            	if(typeof(data[p].access_token) != "undefined"){
	                            	data[p].access_token = usertoken;
                            	}
                                $("#txtParams").val(format(JSON.stringify(data[p])));
                            }
                        }
                    },
                    error:function (res) {
                        alert(res.statusText);
                    }
                });
            });
        });

        function btnSubmit() {
            var address = $("#txtUrl").val();
            var controller = $("#txtConller").val();
            var stype = $("#sType").val();
            var params = $("#txtParams").val();
            if (address == "") {
                return false;
            }
            if (controller == "") {
                alert("请求路径不能为空");
                return false;
            }
            if (stype == "") {
                alert("请求行为必填");
                return false;
            }
            if (params == "") {
                params = null;
            }
            if (params != "") {
                params = JSON.parse(params);
            }
            var rURl = address + controller
            $.ajax({
                url: rURl,
                type: stype,
                data: params,
                dataType: "json",
                success: function (data) {
                	if(data.data[0] && data.data[0].user_token){
                		accesstoken = data.data[0].user_token;
                	}
                	if(data.data[0].access_token){
                		usertoken = data.data[0].access_token;
                	}
                    document.getElementById("modes").innerHTML = CurentTime()+"<br>"+JSON.stringify(data,null,"<p>");
                }
            }).fail(
                    function (xhr, textStatus, err) {
                        var msg = "";
                        if (err == "") {
                            msg = "<span style='color:red;'>服务端错误或服务未启动！</span>";
                        }
                        else {
                            msg = "<span style='color:red;'>" + err + "!</span>";
                        }
                        document.getElementById("modes").innerHTML = CurentTime()+msg;
                    });
        }

        function btnSubmit2() {
            var address = $("#txtUrl").val();
            var controller = $("#txtConller").val();
            var stype = $("#sType").val();
            var params = $("#txtParams").val();
            if (address == "") {
                return false;
            }
            if (controller == "") {
                alert("请求路径不能为空");
                return false;
            }
            if (stype == "") {
                alert("请求行为必填");
                return false;
            }
            if (params == "") {
                params = null;
            }
            if (params != "") {
                params = JSON.parse(params);
            }
            var rURl = address + controller
            $.ajax({
                url: rURl,
                type: stype,
                data: params,
                dataType: "jsonp",
                async: false,
                jsonp: "jsonpcallback", //服务端用于接收callback调用的function名的参数
                success: function(data) {
                    document.getElementById("modes").innerHTML = CurentTime()+"<br>"+JSON.stringify(data,null,"<p>");
                },
                error: function(xhr, textStatus, err){
                    var msg = "";
                    if (err == "") {
                        msg = "<span style='color:red;'>服务端错误或服务未启动！</span>";
                    }
                    else {
                        msg = "<span style='color:red;'>" + err + "!</span>";
                    }
                    document.getElementById("modes").innerHTML = CurentTime()+msg;
                }
            });
        }
        function CurentTime(){
            var now = new Date();
            var year = now.getFullYear();       //年
            var month = now.getMonth() + 1;     //月
            var day = now.getDate();            //日
            var hh = now.getHours();            //时
            var mm = now.getMinutes();          //分
            var ss = now.getSeconds();          //分
            var clock = year + "-";
            if(month < 10)
                clock += "0";
            clock += month + "-";
            if(day < 10)
                clock += "0";
            clock += day + " ";
            if(hh < 10)
                clock += "0";
            clock += hh + ":";
            if (mm < 10) clock += '0';
            clock += mm + ":";
            if (ss < 10) clock += '0';
            clock += ss;
            return("["+clock+"]");
        }

        function format(txt,compress/*是否为压缩模式*/){/* 格式化JSON源码(对象转换为JSON文本) */
            var indentChar = '    ';
            if(/^\s*$/.test(txt)){
                alert('数据为空,无法格式化! ');
                return;
            }
            try{var data=eval('('+txt+')');}
            catch(e){
                alert('数据源语法错误,格式化失败! 错误信息: '+e.description,'err');
                return;
            };
            var draw=[],last=false,This=this,line=compress?'':'\n',nodeCount=0,maxDepth=0;

            var notify=function(name,value,isLast,indent/*缩进*/,formObj){
                nodeCount++;/*节点计数*/
                for (var i=0,tab='';i<indent;i++ )tab+=indentChar;/* 缩进HTML */
                tab=compress?'':tab;/*压缩模式忽略缩进*/
                maxDepth=++indent;/*缩进递增并记录*/
                if(value&&value.constructor==Array){/*处理数组*/
                    draw.push(tab+(formObj?('"'+name+'":'):'')+'['+line);/*缩进'[' 然后换行*/
                    for (var i=0;i<value.length;i++)
                        notify(i,value[i],i==value.length-1,indent,false);
                    draw.push(tab+']'+(isLast?line:(','+line)));/*缩进']'换行,若非尾元素则添加逗号*/
                }else   if(value&&typeof value=='object'){/*处理对象*/
                    draw.push(tab+(formObj?('"'+name+'":'):'')+'{'+line);/*缩进'{' 然后换行*/
                    var len=0,i=0;
                    for(var key in value)len++;
                    for(var key in value)notify(key,value[key],++i==len,indent,true);
                    draw.push(tab+'}'+(isLast?line:(','+line)));/*缩进'}'换行,若非尾元素则添加逗号*/
                }else{
                    if(typeof value=='string')value='"'+value+'"';
                    draw.push(tab+(formObj?('"'+name+'":'):'')+value+(isLast?'':',')+line);
                };
            };
            var isLast=true,indent=0;
            notify('',data,isLast,indent,false);
            return draw.join('');
        }
    </script>
</head>
<body>
<h2>API 测试页面</h2>
<table border="0" cellpadding="0" cellspacing="5">
    <tr>
        <td>请求地址</td>
        <td>
            <input type="text" value="http://127.0.0.1:21600" name="txtUrl" id="txtUrl" maxlength="200"/></td>
    </tr>
    <tr>
        <td>请求路径</td>
        <td>
            <select id="txtConller" name="txtConller">

            </select>
    </tr>
    <tr>
        <td>请求行为</td>
        <td>
            <select id="sType" name="sType">
                <option value="POST">Post</option>
                <option value="GET">Get</option>
            </select>

        </td>
    </tr>
    <tr>
        <td>请求参数</td>
        <td>
            <textarea value="" cols="50" rows="10" style="overflow: auto;" name="txtParams" id="txtParams" placeholder=' 例如：{"Id":"001","Name":"张三","Phone":"2014/4/22 13:18:26","EmailAddress":"dulei@51lsh.com"}'></textarea>
        </td>
    </tr>
    <tr>

        <td colspan="2">
            <input type="button" value="提 交" onclick="btnSubmit()"/>
            <input type="button" value="跨域提交" onclick="btnSubmit2()"/>
        </td>
    </tr>
</table>
<span>返回数据：</span>

    <div id="modes">
    </div>
</body>
</html>
